package com.szl.yeb.controller;


import com.szl.yeb.common.constant.MsgConstant;
import com.szl.yeb.entity.Role;
import com.szl.yeb.common.R;
import com.szl.yeb.service.RoleService;
import com.szl.yeb.utils.ResponseProcessor;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * (Role)表控制层
 *
 * @author szl
 * @since 2022-08-24 16:21:28
 */
@Api(tags = "角色管理接口(RoleController)")
@RestController
@RequestMapping("system/basic/role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @ApiOperation("查询所有角色")
    @GetMapping("/")
    public R<Object> getRoles() {
        return R.obj(roleService.list());
    }

    @ApiOperation(value = "新增角色信息 ")
    @PostMapping("/")
    public R<Object> addRole(@RequestBody Role role) {
        return ResponseProcessor.getResWithMsg(roleService.save(role), MsgConstant.ADD);
    }

    @ApiOperation(value = "删除角色信息")
    @DeleteMapping("/{id}")
    public R<Object> deleteRole(@PathVariable Integer id) {
        return ResponseProcessor.getResWithMsg(roleService.removeById(id), MsgConstant.DELETE);
    }
}

